package com.edu.chongdian.viewmodels;

import android.util.Log;

import com.edu.chongdian.model.User1;

public class VirtualCurrencyManager {
    // 假设每1元映射为10个虚拟货币
    private static final int Beishu = 10;
    // 查询用户的虚拟货币余额
    public int getVirtualCurrencyBalance(int userId) {
        // 假设通过用户ID从数据库中获取用户信息
        User1 user = new User1(userId);
      //  Log.e("TAG","11"+user.getVirtualCurrencyBalance());
        return user.getVirtualCurrencyBalance();
    }
    // 充值用户的虚拟货币余额
    public int rechargeVirtualCurrency(int userId, int rechargeAmount) {
        // 假设通过用户ID从数据库中获取用户信息
        User1 user = new User1(userId);
        if (user == null) {
        }
        int newVirtualCurrencyBalance = user.getVirtualCurrencyBalance() + (rechargeAmount * Beishu);
        user.setVirtualCurrencyBalance(newVirtualCurrencyBalance);
        return newVirtualCurrencyBalance;
    }
    // 消费用户的虚拟货币余额
    public int consumeVirtualCurrency(int userId, int consumeAmount) {
        // 假设通过用户ID从数据库中获取用户信息
        User1 user = new User1(userId);
        if (user == null) {

        }
        int virtualCurrencyBalance = user.getVirtualCurrencyBalance();
        if (virtualCurrencyBalance < (consumeAmount * Beishu)) {
             // 虚拟货币余额不足，消费失败
        }
        int newVirtualCurrencyBalance = virtualCurrencyBalance - (consumeAmount * Beishu);
        Log.e("TAG","消费"+newVirtualCurrencyBalance);
        user.setVirtualCurrencyBalance(newVirtualCurrencyBalance);
        return newVirtualCurrencyBalance;
    }
}
